<?php
/**
 * Created by PhpStorm.
 * User: 小蛮哼哼哼
 * Email: 243194993@qq.com
 * Date: 2022/6/7
 * Time: 15:43
 * motto: 现在的努力是为了小时候吹过的牛逼！
 */

declare(strict_types=1);

namespace app\admin\controller\mall;

use app\admin\traits\Curd;
use app\common\controller\AdminController;
use app\common\lib\Show;
use app\common\lib\Status;
use app\common\model\MachineMachine;
use app\common\model\MallCommissionRecode;
use app\common\model\MallOrder;
use EasyAdmin\annotation\ControllerAnnotation;
use EasyAdmin\annotation\NodeAnotation;

use think\App;

/**
 * @ControllerAnnotation(title="提现管理")
 */
class Withdrawal extends AdminController
{
    use Curd;

    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->model = new MallCommissionRecode();
    }

    /**
     * @NodeAnotation(title="列表")
     * @return array|mixed|\think\response\Json
     */
    public function index()
    {
        if ($this->request->isAjax()) {
            if (input('selectFields')) {
                return $this->selectList();
            }
            list($page, $limit, $where, $map) = $this->buildTableParames([], 'o');
            $lists = $this->model->alias('o')
                ->field("o.*,c.title")
                ->join("machine_cate c", "o.cate_id = c.id")
                ->where($where)
                ->paginate($limit)
                ->toArray();
            return Show::json_show(Status::lay_normal, "ok", $lists['data'], $lists['total']);
        }
        return $this->fetch();
    }

    /**
     * @return void
     * @NodeAnotation(title="修改状态")
     * @throws \think\Exception
     */
    public function status()
    {
        $id = $this->request->param('id',0,'intval');
        $status = $this->request->param('status',0,'intval');
        $res = $this->model->updateDataSave($id, [
            'status' => $status,
            "update_time" => time()
        ]);
        if ($res) {
            $this->success("成功");
        } else {
            $this->error("失败");
        }
    }
}